package com.bobo.controller.front.report;

import com.bobo.annotations.RequestBody;
import com.bobo.annotations.RequestMapping;
import com.bobo.annotations.RequestMethod;
import com.bobo.controller.base.BaseServlet;
import com.bobo.model.Message;
import com.bobo.model.Report;
import com.bobo.model.User;
import com.bobo.service.report.IReportService;
import com.bobo.service.report.ReportServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by bobo on 16-11-3.
 */
@WebServlet(name = "report",urlPatterns = {"/report/*"})
public class ReportContrller extends BaseServlet {

    IReportService reportService = new ReportServiceImpl();

    @RequestBody
    @RequestMapping("/add")
    public String add(HttpServletRequest request, HttpServletResponse response) {
        User user = (User) request.getSession().getAttribute("user");
        int id = Integer.parseInt(request.getParameter("id"));
        String content = request.getParameter("content");

        Report report = new Report();
        report.setContent(content);
        report.setUser(user);
        Message message = new Message();
        message.setId(id);
        report.setMessage(message);

        reportService.create(report);
        return "true";
    }
}
